# -*- coding: utf-8 -*-
"""
 @Time    : 2021/2/2 下午4:37
 @Author  : tgy
 
"""


class MyProperty:
    ...

    def __init__(self, fget=None, fset=None, fdel=None):
        self.fget = fget
        self.fset = fset
        self.fdel = fdel

    def setter(self, fset):
        self.fset = fset
        return self

    def deleter(self, fdel):
        self.fdel = fdel
        return self

    # def __repr__(self):
    #     return self.fget()
    def __get__(self, instance, owner):
        return self.fget(instance)

    def __set__(self, instance, value):
        self.fset(instance,value)

class Person:

    def __init__(self, name):
        self._name = name

    """
    下面属性的函数名必须一致
    """

    # name = property(name)
    # @property
    @MyProperty
    def name(self):
        return self._name

    @name.setter
    def name(self, val):
        self._name = val
    #
    # @name.deleter
    # def name(self):
    #     print('def name')
    def get_name(self):
        return self._name

    def set_name(self, val):
        self._name = val

    def delete_name(self):
        ...

    name1 = property(fget=get_name, fset=set_name, fdel=delete_name)


class Animal:

    def __init__(self):
        self.name = 'lisi'

    def __get__(self, instance, owner):
        print(instance,owner)
        return 'xxx'

class Dog:
    animal = Animal()

if __name__ == '__main__':
    ...
    person = Person(name='tony')
    print(person.name)
    person.name = 'mikey'
    print(person.name)
    # del person.name
    # animal = Animal()
    # print(animal.name)
    # dog = Dog()
    # print(dog)
    # print(dog.animal)
